package com.msstudio;

// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

import com.msstudio.utils.PkgTools;
import com.msstudio.utils.HttpPosterListener;
import com.msstudio.midlets.MSCMIDlet;
import javax.microedition.lcdui.*;

public class MainMenu
    implements CommandListener, HttpPosterListener
{

    private final int C_Menu_Main = 0;
    private final int C_Menu_CurFriend = 1;
    private final int C_Menu_Finger = 2;
    private final int C_Menu_AddFriend = 3;
    private final int C_Menu_SysMsg = 4;
    private final int C_Menu_Control = 5;
    private final int C_Menu_BlackList = 6;
    private final int C_Menu_ClearLogin = 7;
    private final int C_Menu_List = 8;
    private final int C_Menu_ChangeStat = 9;
    private final int C_Menu_Send = 10;
    private final int C_Menu_Receive = 11;
    private final int C_Menu_GetInfor = 12;
    private final int C_Menu_History = 13;
    private final int C_Menu_Delete = 14;
    private final int C_Menu_AddThis = 15;
    private final int C_Menu_AddToBlackList = 16;
    private final int C_Menu_SelfOnline = 50;
    private final int C_Menu_SelfAway = 51;
    private final int C_Menu_SelfInvisible = 52;
    private List menuList;
    private String listItem[];
    private String listItem1[];
    private String listItem3[];
    private String listItem4[];
    private int curMenu;
    private int aMenuIDs[];
    private long curUIN;
    protected Command cmdOk;
    protected Command cmdDel;
    protected Command cmdBackToMainMenu;
    protected Command cmdBackToFriendList;
    protected Command cmdCancel;
    private Form operateForm;

    public MainMenu()
    {
        menuList = null;
        listItem = null;
        listItem1 = null;
        listItem3 = null;
        listItem4 = null;
        aMenuIDs = new int[12];
        cmdOk = null;
        cmdDel = null;
        cmdBackToMainMenu = null;
        cmdBackToFriendList = null;
        cmdCancel = null;
        curMenu = 0;
        curUIN = 0L;
    }

    public void init()
    {
        listItem = (new String[] {
            MSCMIDlet.multiLang.sCurFriend, MSCMIDlet.multiLang.sFinger, 
            MSCMIDlet.multiLang.sAddFriend, MSCMIDlet.multiLang.sSysMessageMenu,
            //MSCMIDlet.multiLang.sFlowControlOff,
            MSCMIDlet.multiLang.sCheckBlackList, 
            MSCMIDlet.multiLang.sRemoveLoginInfor, MSCMIDlet.multiLang.sFriendList, 
            MSCMIDlet.multiLang.sChangeStat
        });
        listItem1 = (new String[] {
            MSCMIDlet.multiLang.sMenuSendMessage, MSCMIDlet.multiLang.sMenuGetInfor, 
            MSCMIDlet.multiLang.sMenuHistory, MSCMIDlet.multiLang.sDeleteFriend, 
            MSCMIDlet.multiLang.sAddToBlackList
        });
        listItem4 = (new String[] {
            MSCMIDlet.multiLang.sOnline, MSCMIDlet.multiLang.sLeave, MSCMIDlet.multiLang.sInvisible
        });
        cmdOk = new Command(MSCMIDlet.multiLang.sYes, 1, 1);
        cmdDel = new Command(MSCMIDlet.multiLang.sDelete, 1, 1);
        cmdBackToMainMenu = new Command(MSCMIDlet.multiLang.sBack, 2, 2);
        cmdBackToFriendList = new Command(MSCMIDlet.multiLang.sBack, 2, 2);
        cmdCancel = new Command(MSCMIDlet.multiLang.sCancel, 2, 2);
    }

    public void deleteFriend(String s)
    {
        MSCMIDlet.httpPoster.delFriend(s, this);
    }

    public void commandAction(Command command, Displayable displayable)
    {
        if(command == cmdOk)
        {
            listAction();
            return;
        }
        if(command == cmdDel)
        {
            MSCMIDlet.mainForm.show();
            deleteFriend(Long.toString(curUIN));
            return;
        }
        if(command == cmdBackToMainMenu)
        {
            showMenu(0);
            return;
        }
        if(command == cmdBackToFriendList || command == cmdCancel)
        {
            MSCMIDlet.mainForm.show();
            return;
        }
        if(command == List.SELECT_COMMAND)
            listAction();
    }

    private void listAction()
    {
        switch(aMenuIDs[menuList.getSelectedIndex()])
        {
        case 1: // '\001'
            showMenu(1);
            break;

        case 8: // '\b'
            showMenu(8);
            break;

        case 2: // '\002'
            MSCMIDlet.finger.show();
            break;

        case 9: // '\t'
            showMenu(9);
            break;

        case 11: // '\013'
            MSCMIDlet.getMsgDlg.show(true, curUIN);
            break;

        case 10: // '\n'
            MSCMIDlet.sendMsgDlg.show(curUIN, false);
            break;

        case 12: // '\f'
            MSCMIDlet.mainForm.show();
            MSCMIDlet.finger.doGetInfor(Long.toString(curUIN), MSCMIDlet.mainForm.GetWindow());
            break;

        case 13: // '\r'
            MSCMIDlet.historyMsg.show(curUIN);
            break;

        case 14: // '\016'
            MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sMSC, MSCMIDlet.multiLang.GetCombineMsg(127, "" + curUIN), this, cmdDel, cmdCancel);
            break;

        case 15: // '\017'
            MSCMIDlet.mainForm.show();
            MSCMIDlet.addFriend.show(MSCMIDlet.mainForm.GetWindow(), Long.toString(curUIN));
            break;

        case 16: // '\020'
            MSCMIDlet.blackList.addToBlack(Long.toString(curUIN), "");
            break;

        case 4: // '\004'
            MSCMIDlet.getMsgDlg.show(false, 0L);
            break;

        case 3: // '\003'
            MSCMIDlet.addFriend.show(MSCMIDlet.mainForm.GetWindow(), null);
            break;

        case 5: // '\005'
            MSCMIDlet.getMsgDlg.switchControl();
            MSCMIDlet.mainForm.show();
            break;

        case 6: // '\006'
            MSCMIDlet.blackList.show();
            break;

        case 7: // '\007'
            PkgTools.setUserInfo("0", "");
            MSCMIDlet.friendList.showInfor(MSCMIDlet.multiLang.sLoginMsgDeleted);
            MSCMIDlet.mainForm.show();
            break;

        case 50: // '2'
            MSCMIDlet.httpPoster.changeStat("10", this);
            MSCMIDlet.friendList.changeSelfState(10);
            MSCMIDlet.mainForm.show();
            break;

        case 51: // '3'
            MSCMIDlet.httpPoster.changeStat("30", this);
            MSCMIDlet.friendList.changeSelfState(30);
            MSCMIDlet.mainForm.show();
            break;

        case 52: // '4'
            MSCMIDlet.httpPoster.changeStat("40", this);
            MSCMIDlet.friendList.changeSelfState(40);
            MSCMIDlet.mainForm.show();
            break;
        }
    }

    public void show(long l)
    {
        curUIN = l;
        showMenu(0);
    }

    public void show()
    {
        showMenu(0);
    }

    private void showMenu(int i)
    {
        curMenu = i;
        switch(i)
        {
        case 2: // '\002'
        case 3: // '\003'
        case 4: // '\004'
        case 5: // '\005'
        case 6: // '\006'
        case 7: // '\007'
        default:
            break;

        case 0: // '\0'
            boolean flag = false;
            boolean flag1 = false;
            menuList = new List(MSCMIDlet.multiLang.sMainMenu, 3, listItem, null);
            int j = 0;
            if(curUIN == 0L)
                flag = true;
            else
                aMenuIDs[j++] = 1;
            aMenuIDs[j++] = 2;
            aMenuIDs[j++] = 3;
            if(MSCMIDlet.getMsgDlg.getSysMsgNum() == 0)
                flag1 = true;
            else
                aMenuIDs[j++] = 4;
            if(!MSCMIDlet.getMsgDlg.getControl())
                menuList.set(4, MSCMIDlet.multiLang.sFlowControlOn, null);
            if(flag1)
                menuList.delete(3);
            if(flag)
                menuList.delete(0);
            int l = 5;
            for(; j < 12; j++)
                aMenuIDs[j] = l++;

            menuList.addCommand(cmdBackToFriendList);
            menuList.setCommandListener(this);
            break;

        case 1: // '\001'
            menuList = new List(MSCMIDlet.multiLang.sCurFriend, 3, listItem1, null);
            menuList.addCommand(cmdBackToMainMenu);
            menuList.setCommandListener(this);
            if(MSCMIDlet.getMsgDlg.findMsgByUIN(curUIN) >= 0)
            {
                aMenuIDs[0] = 11;
                menuList.set(0, MSCMIDlet.multiLang.sReadMessage, null);
            } else
            {
                aMenuIDs[0] = 10;
                menuList.set(0, MSCMIDlet.multiLang.sMenuSendMessage, null);
            }
            aMenuIDs[1] = 12;
            aMenuIDs[2] = 13;
            if(MSCMIDlet.friendList.iGroup == 1)
            {
                aMenuIDs[3] = 14;
            } else
            {
                aMenuIDs[3] = 15;
                menuList.set(3, MSCMIDlet.multiLang.sMenuAddToFriendList, null);
            }
            aMenuIDs[4] = 16;
            break;

        case 8: // '\b'
            operateForm = new Form(MSCMIDlet.multiLang.sFriendList);
            operateForm.append(MSCMIDlet.multiLang.sInst);
            operateForm.addCommand(cmdBackToMainMenu);
            operateForm.setCommandListener(this);
            MSCMIDlet.display.setCurrent(operateForm);
            return;

        case 9: // '\t'
            menuList = new List(MSCMIDlet.multiLang.sChangeStat, 3);
            int k = 0;
            if(MSCMIDlet.friendList.iSelfState != 10)
            {
                aMenuIDs[k++] = 50;
                menuList.append(listItem4[0], null);
            }
            if(MSCMIDlet.friendList.iSelfState != 30)
            {
                aMenuIDs[k++] = 51;
                menuList.append(listItem4[1], null);
            }
            if(MSCMIDlet.friendList.iSelfState != 40)
            {
                aMenuIDs[k++] = 52;
                menuList.append(listItem4[2], null);
            }
            menuList.addCommand(cmdBackToMainMenu);
            menuList.setCommandListener(this);
            break;
        }
        menuList.setSelectedIndex(0, true);
        MSCMIDlet.display.setCurrent(menuList);
    }

    public void receiveHttpResponse(String s)
    {
        String s1 = PkgTools.GetParaVal("CMD", s).toUpperCase();
        String s2 = PkgTools.GetParaVal("RES", s);
        String s3 = PkgTools.GetParaVal("SEQ", s);
        if(s1.equals("DELFROMLIST") && s2.equals("0"))
        {
            MSCMIDlet.friendList.showInfor(MSCMIDlet.multiLang.sDeleteSucceed);
            String s4 = MSCMIDlet.httpPoster.getUINbySeq(s3);
            if(s4 == null)
                return;
            MSCMIDlet.friendRecord.deleteRecord(s4);
            MSCMIDlet.friendRecord.addStrangerRecord(s4);
            MSCMIDlet.friendList.buildFriendList();
        }
    }

    public void handleHttpError(String s)
    {
    }
}
